<template>
  <div class="dialogComponents">
    <el-dialog
      v-model="dialogVisible"
      class="dialog-class"
      :width="width"
      :close-on-click-modal="closeOnClickModal"
    >
      <div v-if="headerStatus" class="header">
        <div v-if="!!title" class="headerName">{{ title }}</div>
        <el-icon
          v-if="hideClose"
          size="24"
          style="cursor: pointer"
          @click="closeChange"
        >
          <Close />
        </el-icon>
        <slot name="icon"></slot>
      </div>
      <el-divider v-if="headerStatus" />
      <slot v-if="dialogVisible"></slot>
      <!-- 我添加的 -->
      <template #footer>
        <slot name="footer"></slot>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref } from 'vue';
import bus from '@/utils/bus.js';

const dialogVisible = ref(false);
const { width, title, isSendBus, hideClose } = defineProps({
  title: {
    type: String, // 接收的参数类型
    default: '', //默认值
  },
  width: {
    type: String,
    default: '1200',
  },

  headerStatus: {
    type: Boolean,
    default: true,
  },
  isSendBus: {
    type: Boolean,
    default: false,
  },
  hideClose: {
    type: Boolean,
    default: true,
  },
  closeOnClickModal: {
    type: Boolean,
    default: true,
  },
});

function openChange() {
  dialogVisible.value = true;
}

function closeChange() {
  dialogVisible.value = false;
  if (isSendBus) {
    bus.emit('refreshList');
  }
}
defineExpose({
  openChange,
  closeChange,
});
</script>
<style lang="scss">
.dialog-class {
  border-radius: 6px;

  .el-dialog__header {
    display: none;
  }
}
</style>
<style lang="scss" scoped>
.header {
  display: flex;
  justify-content: space-between;

  .headerName {
    font-size: 18px;
    font-family:
      PingFang SC-Medium,
      PingFang SC;
    font-weight: 600;
    color: #1d2129;
    line-height: 27px;
  }
}
</style>
